<!DOCTYPE html>
<html>
  <head>
    <title>PicoRuby WASM Demo</title>
    <meta charset="utf-8">
  </head>
  <body>
    <div>Example using published npm package</div>
    <ul>
      <li><a href="dom.html">DOM manipulation</a></li>
      <li><a href="multitasks.html">Multi tasks</a></li>
      <li><a href="prime_numbers.html">Prime numbers</a></li>
      <li><a href="rubino_demo.html">Rubino demo</a></li>
    </ul>
    <h1>PicoRuby WASM Demo</h1>
    <h2 id="container">0</h2>
    <button id="switch">Start</button>
    <div id="logo"></div>

    <script type="text/ruby">
      require 'js'
      JS.document.getElementById('switch').addEventListener('click') do |event_json|
        puts event_json # The `event_json` can be parsed by JSON.parse
        sub_task = Task.get('sub_task')
        if sub_task.status == "SUSPENDED"
          sub_task.resume
          JS.document.getElementById('switch').innerText = 'Suspend'
          lvar = :hey
          logo = JS.document.getElementById('logo')
          JS.global.fetch('favicon.ico') do |response|
            if response.status.to_poro == 200
              logo.innerHTML = response.to_binary
            end
          end
        else
          sub_task.suspend
          JS.document.getElementById('switch').innerText = 'Resume'
          JS.document.getElementById('logo').innerHTML = ''
        end
      end
    </script>

    <script type="text/ruby">
      require 'js'
      task = Task.current
      task.name = 'sub_task'
      task.suspend
      container = JS.document.getElementById('container')
      i = 1
      while true
        sleep 1
        container.innerText = i.to_s
        i += 1
      end
    </script>

    <script src="init.iife.js"></script>
  </body>
</html>
